// 导出页面为PDF格式
import html2Canvas from 'html2canvas'
import JsPDF from 'jspdf'

export function getPdf(title, id, pageScale) {
  return new Promise((resolve, reject) => {
    const canvasBox = document.querySelector('body')
    html2Canvas(canvasBox, {
      width: canvasBox.clientWidth - 112,
      height: canvasBox.clientHeight - 160,
      x: 112,
      y: 160,
      scrollX: 0,
      scrollY: 0,
      scale: 4,
      logging: false,
      useCORS: true
    }).then(function (canvas) {
      let contentWidth = canvasBox.clientWidth - 112
      let contentHeight = canvasBox.clientHeight - 160
      let pageData = canvas.toDataURL('image/png', 1)
      let PDF = new JsPDF('l', 'pt', [contentWidth, contentHeight])
      PDF.addImage(pageData, 'PNG', 0, 0, contentWidth, contentHeight)
      PDF.save(title + '.pdf')
      resolve()
    })
  })
}
